from selenium.webdriver.common.by import By
from common.base import Base
from common.functions import open_browser


class OrderManagementPage(Base):
    order_management_url = 'http://139.129.26.163/admin/index.php'

    # 点击订单管理
    def click_order_management(self):
        frame1 = self.find_element((By.ID, 'menu-frame'))
        self.driver.switch_to.frame(frame1)
        self.click((By.XPATH, '//div[@id="menu-list"]/ul/li[4]'))

    # 点击订单列表
    # def click_order_list(self):
        # 再切换进新的frame页面
        # frame2 = self.find_element((By.ID, 'header-frame'))
        # self.driver.switch_to.frame(frame2)
        # self.click((By.LINK_TEXT, '订单列表'))

    # 点击订单号
    def click_order_number(self, content):
        # 先返回父级frame
        # self.driver.switch_to.parent_frame()
        # 切换到新的frame页面
        self.driver.switch_to.default_content()
        frame2 = self.find_element((By.XPATH, '//frameset[@framespacing="0"]/frame[2]'))
        self.driver.switch_to.frame(frame2)
        self.send_keys((By.XPATH, '//html/body/div[@class="form-div"]/form/input[@name="order_sn"]'), content)

    # 点击收货人
    def click_order_people(self, content):
        # 先返回父级frame
        # self.driver.switch_to.parent_frame()
        # 在切换到新的frame页面
        # frame3 = self.find_element((By.XPATH, '//frameset[@id="frame-body"]/frame'))
        # self.switch_to_frame(frame3)
        self.send_keys((By.ID, 'consignee'), content)

    # 下拉框选择订单状态
    def click_order_state(self, index):
        # 先返回父级frame
        # self.driver.switch_to.parent_frame()
        # 在切换到新的frame页面
        # frame3 = self.find_element((By.XPATH, '//frameset[@id="frame-body"]/frame'))
        # self.switch_to_frame(frame3)
        self.select_by_index((By.ID, 'status'), index)

    # 点击搜索
    def click_search(self):
        # 先返回父级frame
        # self.driver.switch_to.parent_frame()
        # 在切换到新的frame页面
        # frame3 = self.find_element((By.XPATH, '//frameset[@id="frame-body"]/frame'))
        # self.switch_to_frame(frame3)
        self.click((By.CLASS_NAME, 'button'))

    # 点击查看
    def click_check(self):
        # self.click((By.XPATH, '//html/body/form/div[@id="listDiv"]/table/tbody/tr[3]/td[7]/a'))
        self.click((By.LINK_TEXT, '查看'))


if __name__ == '__main__':
    browser = open_browser()
    case = OrderManagementPage(browser)
    case.get('http://139.129.26.163/admin/index.php')
    case.click_order_management()
    # case.click_order_list()
    case.click_order_number('2022070672731')
    case.click_order_people('sss')
    case.click_order_state(2)
    case.click_search()
    case.click_check()
